import {
  doPariseApi,
  cancelPariseApi
} from '@/api/praise.js'

// 判断执行sheet弹窗
export function executePariseActionSheet(praiseStatus, params,callback = () => {}) {
  uni.showActionSheet({
    itemList: [`${praiseStatus?'取消喜欢':'喜欢'}`],
    async success(res) {
      if (res.tapIndex === 0) {
        doPariseFunc(praiseStatus,params,callback)
      }
    }
  })
}
// 执行添加/取消喜欢
export async function doPariseFunc(praiseStatus, params, callback = () => {}) {
  const {
    code: resCode,
    data: resData
  } = praiseStatus ? await cancelPariseApi(params) : await doPariseApi(params)
  if (resCode === '000000') {
    callback?.()
    uni.showToast({
      icon: 'none',
      title: praiseStatus ? '已取消喜欢' : '已添加至喜欢'
    })
  }
}
